package com.atguigu.vod.controller;

import com.atguigu.commonutils.Result;
import com.atguigu.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "阿里云视频点播微服务")
@RestController
//@CrossOrigin
@RequestMapping("/edu/vod/video")
public class VodController {
    @Autowired
    private VodService vodService;

    @PostMapping("uploadAliYunVideo")
    public Result uploadAliYunVideo(
            @ApiParam(name = "file", value = "文件", required = true)
                    MultipartFile file) {
        String videoId = vodService.uploadAliYunVideo(file);
        Map map = new HashMap();
        map.put("videoId", videoId);
        return Result.ok(map);
    }

    // 根据视频Id删除视频
    @DeleteMapping("removeAliYunVideo/{videoId}")
    public Result removeAliYunVideo(@PathVariable String videoId) {
        vodService.removeAliYunVideo(videoId);
        return Result.ok();
    }

    @DeleteMapping("removeBatch")
    public Result removeBatchAliYunVideos(@RequestParam("videoIdList") List<String> videoIdList) {
        vodService.removeBatchAliYunVideos(videoIdList);
        return Result.ok();
    }

    @GetMapping("getPlayAuth/{videoId}")
    public Result getPlayAuth(@PathVariable String videoId) {
        String playAuth = vodService.getPlayAuth(videoId);
        return Result.ok(playAuth).message("获取凭证成功");
    }
}
